<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h4 class="modal-title">赠送优惠券</h4>
</div>
<div class="modal-body">
    <form role="form" class="form-horizontal">
        <input type="hidden" name="storeId" value="2017060000000001"/>
        <input type="hidden" name="accountId" value="${accountId}"/>
        <div class="row">
            <div class="col-xs-12">
                <div class="form-group">
                    <label for="couponId" class="col-sm-2 control-label">优惠券</label>
                    <div class="col-sm-8">
                        <select id="couponId" name="couponId" class="form-control">
                            <!--#for(o in couponList!){#-->
                            <option value="${o.id!}" >${o.name!}</option>
                            <!--#}#-->
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">赠送张数</label>
                    <div class="col-sm-8">
                       <!-- <div class="input-group" style="width: 100px; min-width: 80px;">
                            <span class="input-group-btn">
                                <button class="btn btn-default js-coupon-num-minus" type="button">-</button>
                            </span>-->
                            <input type="text" name="num" class="form-control js-coupon-num" value="1">
                          <!--  <span class="input-group-btn">
                                <button class="btn btn-default js-coupon-num-plus" type="button">+</button>
                            </span>
                        </div>-->
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">${msg['globals.button.cancel']}</button>
    <button type="button" class="btn btn-primary js-coupon-select-ok" data-loading-text="${msg['globals.button.submit.tip']}">${msg['globals.button.confirm']}</button>
</div>
<script type="text/javascript">
    $(function () {
        var dialogCoupon = $("#dialogCoupon");
        $("#couponId", dialogCoupon).select2({
            language: "${lang!'zh-CN'}",
            width: "100%", //设置下拉框的宽度
            placeholder: "请选择"
        });
        var $num = $(".js-coupon-num", dialogCoupon);
        $(".js-coupon-num-minus", dialogCoupon).click(function () {
            $num.val(parseInt($num.val())-1);
        });
        $(".js-coupon-num-plus", dialogCoupon).click(function () {
            $num.val(parseInt($num.val())+1);
        });
        $(".js-coupon-select-ok", dialogCoupon).click(function () {
            var data = {
                storeId: $("input[name='storeId']").val(),
                couponId: $("select[name='couponId']").val(),
                accountId: $("input[name='accountId']").val(),
                num: $("input[name='num']").val(),
            }
            $.post("${base}/platform/member/account/couponDo", data, function (ret) {
                if (ret.code == 0) {
                    Toast.success(ret.msg);
                    dialogCoupon.modal("hide");
                } else if (ret.code == 102) {
                    Toast.success(ret.msg);
                } else {
                    Toast.error(ret.msg);
                }
            }, "json");
        });
    });
</script>